package api

import (
	"2302a/testyuekao/api/handler"
	"2302a/testyuekao/api/middleware"
	"2302a/testyuekao/consts"
	"2302a/testyuekao/pkg"
	"github.com/gin-gonic/gin"
)

func LoadRouter(r *gin.Engine) {
	r.Use(middleware.Cors())
	api := r.Group("api")
	{
		user := api.Group("user")
		{
			user.POST("/register", handler.UserRegister)
			user.POST("/login", handler.UserLogin)
			user.POST("file", handler.FileUpload)
			user.Use(pkg.AuthJwt(consts.JWT_KEY))
			user.POST("/refresh", handler.RefreshToken)
		}
		house := api.Group("house")
		{
			house.Use(pkg.AuthJwt(consts.JWT_KEY))
			house.POST("/add", handler.AddHouse)        //实现房源发布接口
			house.GET("/list", handler.ListHouse)       //实现房源列表接口
			house.POST("/update", handler.UpdateHouse)  //实现房源修改接口
			house.GET("/details", handler.DetailsHouse) //提供房源详情接口
		}
		reservation := api.Group("reservation")
		{
			reservation.Use(pkg.AuthJwt(consts.JWT_KEY))
			reservation.POST("/achieve", handler.AchieveReservation) //实现预约
			reservation.POST("/cancel", handler.CancelReservation)   //实现预约
		}
		chat := api.Group("chat")
		{
			chat.Use(pkg.AuthJwt(consts.JWT_KEY))
			chat.GET("/ws", handler.Chat) //聊天
		}
		order := api.Group("order")
		{
			order.Use(pkg.AuthJwt(consts.JWT_KEY))
			order.POST("/add", handler.AddOrder)                        //创建购房
			order.POST("/voucher", handler.VoucherOrder)                //上传首付款凭证
			order.GET("/admin/view", handler.AdminViewOrder)            //管理员查看订单接口
			order.POST("/admin/update", handler.AdminUpdateStatusOrder) //管理员修改订单状态接口
		}
		bullet := api.Group("bullet")
		{
			bullet.Use(pkg.AuthJwt(consts.JWT_KEY))
			bullet.POST("/add", handler.AddBullet) //创建弹幕
		}
		//		admin := api.Group("admin")
		//		{
		//
		//		}
	}
}
